
<template>
  <div class="min-h-screen bg-gray-50 py-8">
    <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
      <!-- 用户信息 -->
      <div class="bg-white rounded-2xl shadow-lg p-8 mb-8">
        <div class="flex items-center space-x-6">
          <div class="w-20 h-20 bg-gradient-to-br from-qinghua-blue to-qinghua-light rounded-full flex items-center justify-center">
            <i class="fas fa-user text-white text-2xl"></i>
          </div>
          <div>
            <h1 class="text-2xl font-bold text-gray-900">我的收藏</h1>
            <p class="text-gray-600">共收藏 {{ collections.length }} 件作品</p>
          </div>
        </div>
      </div>
      
      <!-- 收藏列表 -->
      <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8">
        <div 
          v-for="item in collections" 
          :key="item.id"
          class="bg-white rounded-2xl shadow-lg overflow-hidden hover:shadow-2xl transition-all duration-300"
        >
          <!-- 图片区域 -->
          <div class="aspect-square bg-gradient-to-br from-qinghua-blue to-qinghua-light relative">
            <div class="absolute inset-0 flex items-center justify-center">
              <div class="text-white text-center">
                <i class="fas fa-cube text-6xl mb-4 opacity-50"></i>
                <h3 class="text-xl font-bold">{{ item.name }}</h3>
              </div>
            </div>
            
            <!-- 移除按钮 -->
            <button 
              @click="removeFromCollection(item.id)"
              class="absolute top-4 right-4 bg-red-500 text-white p-2 rounded-full hover:bg-red-600 transition-colors"
            >
              <i class="fas fa-times"></i>
            </button>
          </div>
          
          <!-- 信息区域 -->
          <div class="p-6">
            <h3 class="text-lg font-bold text-qinghua-blue mb-2">{{ item.name }}</h3>
            <p class="text-2xl font-bold text-qinghua-blue mb-4">¥{{ item.price }}</p>
            
            <div class="flex space-x-2">
              <button 
                @click="shareItem(item)"
                class="flex-1 bg-qinghua-blue text-white py-2 rounded-lg text-sm font-semibold hover:bg-opacity-90 transition-colors"
              >
                <i class="fas fa-share-alt mr-1"></i>
                分享
              </button>
              <button 
                @click="viewProduct(item.id)"
                class="flex-1 border border-qinghua-blue text-qinghua-blue py-2 rounded-lg text-sm font-semibold hover:bg-qinghua-blue hover:text-white transition-colors"
              >
                <i class="fas fa-eye mr-1"></i>
                查看
              </button>
            </div>
          </div>
        </div>
      </div>
      
      <!-- 空状态 -->
      <div v-if="collections.length === 0" class="text-center py-20">
        <i class="fas fa-heart-broken text-6xl text-gray-300 mb-4"></i>
        <h3 class="text-xl font-semibold text-gray-600 mb-2">暂无收藏</h3>
        <p class="text-gray-500 mb-6">快去发现更多精美的青花瓷娃娃吧</p>
        <button 
          @click="$router.push('/')"
          class="bg-qinghua-blue text-white px-6 py-3 rounded-xl font-semibold hover:bg-opacity-90 transition-colors"
        >
          去逛逛
        </button>
      </div>
      
      <!-- 分享海报模态框 -->
      <div v-if="showShareModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50">
        <div class="bg-white rounded-2xl p-8 max-w-md w-full mx-4">
          <h3 class="text-xl font-bold text-center mb-4">分享海报</h3>
          <div class="aspect-square bg-gradient-to-br from-qinghua-blue to-qinghua-light rounded-xl flex items-center justify-center mb-4">
            <div class="text-white text-center">
              <i class="fas fa-cube text-4xl mb-2 opacity-50"></i>
              <h4 class="text-lg font-bold">{{ shareItemData.name }}</h4>
              <p class="text-sm opacity-75">青花泡泡限量珍藏</p>
            </div>
          </div>
          
          <div class="flex space-x-4">
            <button 
              @click="downloadPoster"
              class="flex-1 bg-qinghua-blue text-white py-3 rounded-lg font-semibold hover:bg-opacity-90 transition-colors"
            >
              <i class="fas fa-download mr-2"></i>
              下载海报
            </button>
            <button 
              @click="showShareModal = false"
              class="flex-1 border border-gray-300 text-gray-700 py-3 rounded-lg font-semibold hover:bg-gray-50 transition-colors"
            >
              取消
            </button>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { useCollectionStore } from '@/stores/collection'

const router = useRouter()
const collectionStore = useCollectionStore()

const collections = ref(collectionStore.collections)
const showShareModal = ref(false)
const shareItemData = ref({})

const removeFromCollection = (id) => {
  collectionStore.removeFromCollection(id)
  collections.value = collectionStore.collections
}

const shareItem = (item) => {
  shareItemData.value = item
  showShareModal.value = true
}

const viewProduct = (id) => {
  router.push(`/product/${id}`)
}

const downloadPoster = () => {
  // 模拟下载海报
  alert('海报已生成，请在相册中查看')
  showShareModal.value = false
}
</script>
